﻿using System;
using QFramework;

namespace ProjectSurvivor
{
    public class ExpUpgradeItem
    {
        public bool IsWeapon = false; // 是否是武器
        public string Key { get; private set; }
        public string Description => mDescriptionFactory(CurrentLevel.Value + 1);
        public bool UpgradeFinish { get; set; } = false;
        public int MaxLevel { get; private set; }
        
        public string IconName { get; private set; }
        public string Name { get; private set; }
        
        public string PairedName { get; private set; }
        public string PairedDescription { get; private set; }
        public string PairedIconName { get; private set; }
        
        
        public BindableProperty<int> CurrentLevel = new BindableProperty<int>(0);
        public BindableProperty<bool> Visible = new BindableProperty<bool>(false);

        public ExpUpgradeItem(bool isWeapon)
        {
            IsWeapon = isWeapon;
        }
        
        public void Upgrade()
        {
            CurrentLevel.Value++;
            mOnUpgrade?.Invoke(this, CurrentLevel.Value);
            if (CurrentLevel.Value >= MaxLevel)
            {
                UpgradeFinish = true;
            }
        }
        

        private Action<ExpUpgradeItem, int> mOnUpgrade;

        private Func<ExpUpgradeItem, bool> mCondition;
        private Func<int, string> mDescriptionFactory;

        public ExpUpgradeItem WithKey(string key)
        {
            Key = key;
            return this;
        }
        
        public ExpUpgradeItem WithDescription(Func<int, string> descriptionFactory)
        {
            mDescriptionFactory = descriptionFactory;
            return this;
        }

        public ExpUpgradeItem OnUpgrade(Action<ExpUpgradeItem, int> onUpgrade)
        {
            mOnUpgrade = onUpgrade;
            return this;
        }

        public ExpUpgradeItem WithMaxLevel(int maxLevel)
        {
            MaxLevel = maxLevel;
            return this;
        }
        
        public ExpUpgradeItem WithIconName(string name)
        {
            IconName = name;
            return this;
        }
        
        public ExpUpgradeItem WithName(string name)
        {
            Name = name;
            return this;
        }
        
        public ExpUpgradeItem WithPairedIconName(string name)
        {
            PairedIconName = name;
            return this;
        }
        public ExpUpgradeItem WithPairedName(string name)
        {
            PairedName = name;
            return this;
        }
        public ExpUpgradeItem WithPairedDescription(string name)
        {
            PairedDescription = name;
            return this;
        }
    }
}